﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
@using Microsoft.AspNetCore.Antiforgery
@inject IAntiforgery Antiforgery
<style>
    .title-with-border {
        border-left: 4px solid #007BFF; /* 蓝色竖线，宽度为4px */
        padding-left: 10px; /* 文字与边框的间距 */
        font-size: 18px; /* 文字大小 */
        font-weight: bold; /* 文字加粗 */
        color: #333; /* 文字颜色 */
    }

    .text-input {
        margin-bottom: 20px; /* 每个文本框下方留出20px的间距 */
        width: 100%;
    }

    .button-container {
        display: flex;
        justify-content: flex-end; /* 内容靠右对齐 */
        gap: 10px; /* 按钮之间的间距（可选） */
        justify-content: center; /* 小屏幕居中对齐 */
    }

    .search-btn {
        position: absolute;
        right: 5px;
        top: 50%;
        transform: translateY(-50%);
        cursor: pointer;
        color: #1E9FFF;
    }

    .layui-input-inline {
        position: relative;
    }

    .quantity-control {
        display: flex;
        align-items: center;
    }

    .quantity-btn {
        width: 30px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        border: 1px solid #e6e6e6;
        cursor: pointer;
        user-select: none;
    }

    .quantity-input {
        width: 60px !important;
        text-align: center;
        margin: 0 5px;
    }
</style>
<link href="~/scripts/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
<body>
    <div class="title-with-border">生产报工</div>
    <form class="layui-form layui-form-disabled" action="" lay-filter="viewForm">
        @Html.AntiForgeryToken()
        <input type="hidden" id="reportId" name="id" value="" readonly disabled />
        <div class="layui-form-item">
            <label class="layui-form-label">报工类型</label>
            <div class="layui-input-inline">
                <input type="text" name="reportingType" class="layui-input" readonly disabled>
            </div>
            <label class="layui-form-label">生产工单</label>
            <div class="layui-input-inline">
                <input type="text" id="workOrder" name="productionWorkOrderCode" class="layui-input" readonly disabled>
            </div>
            <label class="layui-form-label">生产任务</label>
            <div class="layui-input-inline">
                <input type="text" id="productionTask" name="productionTask" class="layui-input" readonly disabled>
            </div>
            <label class="layui-form-label">报工人</label>
            <div class="layui-input-inline">
                <input type="text" id="reporter" name="reporter" class="layui-input" readonly disabled>
            </div>
            <label class="layui-form-label">审核人</label>
            <div class="layui-input-inline">
                <input type="text" id="reviewer" name="approver" class="layui-input" readonly disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">产品编码</label>
            <div class="layui-input-inline">
                <input type="text" id="productCode" name="productMaterialCode" class="layui-input" readonly disabled>
            </div>
            <label class="layui-form-label">产品名称</label>
            <div class="layui-input-inline">
                <input type="text" id="productName" name="productMaterialName" class="layui-input" readonly disabled>
            </div>
            <label class="layui-form-label">单位</label>
            <div class="layui-input-inline">
                <input type="text" id="unit" name="unit" class="layui-input" readonly disabled>
            </div>
            <label class="layui-form-label">规格型号</label>
            <div class="layui-input-inline">
                <input type="text" id="productModel" name="productModel" class="layui-input" readonly disabled>
            </div>
            <label class="layui-form-label">工作站名称</label>
            <div class="layui-input-inline">
                <input type="text" id="workstationName" name="workstationName" class="layui-input" readonly disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">报工数量</label>
            <div class="layui-input-inline">
                <input type="text" id="reportQuantity" name="reportingQuantity" class="layui-input" readonly disabled>
            </div>
            <label class="layui-form-label">待检测数量</label>
            <div class="layui-input-inline">
                <input type="text" id="inspectionQuantity" name="detectNumber" class="layui-input" readonly disabled>
            </div>
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <input type="text" id="statesText" name="statesText" class="layui-input" readonly disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark" class="layui-textarea text-input" style="width: 700px; height: 150px;" readonly disabled></textarea>
            </div>
        </div>
        <div class="layui-form-item form-actions button-container">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-primary" onclick="returnquery()">
                    <i class="layui-icon layui-icon-return"></i> 返回
                </button>
            </div>
        </div>
    </form>
</body>
<script src="~/scripts/jquery-3.4.1.min.js"></script>
<script src="~/scripts/layui-v2.5.6/layui/layui.js"></script>
<script>
    layui.use(['form', 'layer'], function(){
        var form = layui.form;
        var layer = layui.layer;
        
        // 获取URL中的id参数
        var urlParams = new URLSearchParams(window.location.search);
        var id = urlParams.get('id');
        
        // 如果有id参数，则加载数据
        if (id) {
            loadReportData(id);
        }

        // 加载报工数据的函数
        function loadReportData(id) {
            $.ajax({
                url: '/ProductionReport/FindProductionWorkOrderMain',
                type: 'GET',
                data: { id: id },
                success: function(data) {
                    if (data) {
                        // 填充表单数据
                        $('#reportId').val(data.id);
                        $('input[name="reportingType"]').val(data.reportingType);
                        $('input[name="productionWorkOrderCode"]').val(data.productionWorkOrderCode);
                        $('input[name="productionTask"]').val(data.productionTask);
                        $('input[name="unit"]').val(data.unit);
                        $('input[name="productModel"]').val(data.productModel);
                        $('input[name="productMaterialCode"]').val(data.productMaterialCode);
                        $('input[name="productMaterialName"]').val(data.productMaterialName);
                        $('input[name="reporter"]').val(data.reporter);
                        $('input[name="approver"]').val(data.approver);
                        $('input[name="workstationName"]').val(data.workstationName);
                        
                        $('#reportQuantity').val(data.reportingQuantity);
                        $('#inspectionQuantity').val(data.detectNumber);
                        
                        // 设置状态文本
                        var statesText = '';
                        switch(data.states) {
                            case 1: statesText = '草稿'; break;
                            case 2: statesText = '审核中'; break;
                            case 3: statesText = '已完成'; break;
                            case 4: statesText = '已拒绝'; break;
                            default: statesText = '未知状态';
                        }
                        $('#statesText').val(statesText);
                        
                        $('textarea[name="remark"]').val(data.remark);

                        form.render();
                    } else {
                        layer.msg('未找到相关数据', {icon: 2});
                    }
                },
                error: function(xhr, status, error) {
                    layer.msg('加载数据失败：' + error, {icon: 2});
                }
            });
        }
    });

    function returnquery(){
        location.href = "/ProductionReport/ProductionReportView"
    }
</script>